//
//  JJPrecompile.h
//  DemoPro
//
//  Created by vpjacob on 2017/4/7.
//  Copyright © 2017年 vpjacob. All rights reserved.
//

#ifndef JJPrecompile_h
#define JJPrecompile_h


#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__);
#else
#define NSLog(...)
#endif

//主代理
#define JJ_AppDelegate  ((AppDelegate *)[UIApplication sharedApplication].delegate)

//单例宏定义.h
#define JJ_DEFINE_SINGLETON_FOR_HEADER(className) \
\
+ (className *)shareInstance;

//单例宏定义.m
#define JJ_DEFINE_SINGLETON_FOR_CLASS(className) \
\
+ (className *)shareInstance { \
static className *instance = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
instance = [[self alloc] init]; \
}); \
return instance; \
}

//色值宏定义
#define JJ_RGBA(r,g,b,a)   [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
#define JJ_RGB(r,g,b)   JJ_RGBA(r,g,b,1.0)

//字体大小
#define JJ_FONT_SIZE_DEFAULT(size) [UIFont systemFontOfSize:size]
#define JJ_FONT_SIZE_BOLD(size)    [UIFont boldSystemFontOfSize:size]

//当前系统版本
#define JJ_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

//App版本
#define JJ_APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//设备屏幕高度
#define JJ_SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height

//设备屏幕宽度
#define JJ_SCREEN_WIDTH  [[UIScreen mainScreen] bounds].size.width

//屏幕大小
#define JJ_SCREEN_BOUNDS [[UIScreen mainScreen] bounds]

//沙盒路径
#define JJ_PATH_SANDBOX    ( NSHomeDirectory() )
#define JJ_PATH_DOCUMENTS  ( NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] )
#define JJ_PATH_LIBRARY    ( NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0] )
#define JJ_PATH_CACHE      ( NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] )
#define JJ_PATH_TMP        ( NSTemporaryDirectory() )


//weakSelf
#define JJ_WS(weakSelf)  __weak __typeof(self)weakSelf = self;

//strongSelf
#define JJ_SS(strongSelf, weakSelf) __strong __typeof(weakSelf)strongSelf = weakSelf;

/// weakSelf
#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif

/// strongSelf
#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif




#endif /* JJPrecompile_h */
